<style type="text/css" media="screen">
    .div-delete {
        margin:1em;
        width:250px;
    }
    table#page-list td {
        border-bottom:1px solid #c3cccc;
        border-top:1px solid #f3f3f3;
        margin-bottom:1px;
    }
    #add_new {
        margin-bottom:1em;
        border-bottom:3px solid #f6f6f6;
    }
    .goright {
        text-align:right;
    }
</style>
<h1>Page Management</h1>

<div id='add_new' class='yui-g'>
    <div class='yui-u first'>
        <p><?php echo link_to('Add New Page',array('controller'=>'admin/pages')); ?></p>
    </div>
    <div class='yui-u goright'>
        <?php echo  form_tag('search_pages',array('method'=>'get')) ?>    
        Search By Page Title: <?php echo  text_field_tag('title',null,array('id'=>'title','size'=>40)) ?>            
        <div class="auto_complete" id="auto_complete"></div>
        <?php echo submit_tag('Edit')?>
        <script type="text/javascript">new Ajax.Autocompleter('title', 'auto_complete', '<?php echo  url_for('search_pages') ?>', {})</script>
        <?php echo  end_form_tag() ?>
    </div>
</div>

<?php echo error_messages_for('pages')?>

<?php if($pages->is_loaded()) {
            echo "<h2>Managing Page: <span style='color:red'>".$pages->get('title')."</span> [";
            echo link_to('view', 
                         array('controller'=>'content' ,'action'=>$pages->get('index_name')),
                         array('target'=>'_blank'));
            echo "]</h2>"; ?>

<p><b>The URL to this page is: </b>
<?php echo link_to("http://".$_SERVER['HTTP_HOST'].$pages->url(),
                   "http://".$_SERVER['HTTP_HOST'].$pages->url()) ?></p>
<?php } ?>

<?php
// figure out current home page stuffs.
$current_index_page = $pages->get_index_page();
?>


<?php
    if ( !$pages->is_loaded() )
    {
?>

<div id='tabsmenu'>
    <ul id='tabs'>
        <li><a href="#tab1">All Pages</a></li>
        <li><a href="#tab2">Add Page</a></li>
    </ul>
</div>

<div id='tab1' class='tab-page'>
    <table border="0" cellspacing="5" cellpadding="5" id="page-list" width="100%">
        <tr>
            <th>ID</th>
            <th>Page Title</th>
            <th colspan='3'>Actions</th>
        </tr>
        <?php echo $pages->pages_to_td_cached() ?>
    </table>
</div>

<div id='tab2' class='tab-page'>
<h3>Add Page</h3>      
<?php echo form_tag('add',array('validation'=>true))?>
<?php include load_template('_form.php')?>
<?php echo submit_tag('Add Page')?>
<?php echo end_form_tag()?>
</div>

<?php } else { ?>
    <div id='tabsmenu'>
        <ul id='tabs'>
            <li><a href="#tab1">Content Selection</a></li>
            <li><a href="#tab2">Details</a></li>
            <li><a href="#tab5">Sub Page Order</a></li>
            <li><a href="#tab6">Related Pages</a></li>
            <li><a href="#tab7">Custom Fields</a></li>
            <li><a href="#tab4">Page Permissions</a></li>
        </ul>
    </div>
  
   <div id="tab1" class='tab-page'>
         <?php include load_template('_content.php') ?>
      </div>
      
    <div id="tab2" class='tab-page'>
        <?php include load_template('_page_details.php') ?>
    </div>

   
   <div id="tab5" class='tab-page'>
        <h3>Sub Page Order</h3>
        <?php
        if ($subs = $pages->has_children()) {
            include load_template('_reorder.php');
        } else {
            echo content_tag('p','Page has no children');
        }
        ?>
   </div>
   
   <div id="tab6" class='tab-page'>
       <?php include load_template('_relationship.php') ?>
   </div>
   
   <div id="tab7" class='tab-page'>
        <?php include load_template('_custom_fields.php') ?>
   </div>
   
   
   <?php if ( has_access_to("Pages::Lock Pages")) { ?>
   <div id='tab4' class='tab-page'>
        <?php include load_template('_permissions.php') ?>
   </div>
   <?php } ?>
       

<?php } ?>

<?php if(empty($current_index_page)) { ?>
<div class='section'>
    <p><b>NOTE:</b> You don't currently have a page set as your index (home) page. This might be intended if you have an index.html file in your public directory.
        <?php 
        if(file_exists(PUBLIC_HTML.'/index.html') || file_exists(PUBLIC_HTML.'/index.htm')) { 
            echo '<b>(You Do)</b>'; 
        } else { 
            echo '<b>(You Don\'t)</b>'; 
        } ?>
         But if you don't the system will try to render the home page you set here as your home page.
</div>
<?php } ?>
